package com.ruoyi.stuinfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.grade.domain.Grade;
import com.ruoyi.grade.domain.Gradetemplate;
import com.ruoyi.stuinfo.domain.StuRewards;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stuinfo.domain.StudentPunish;
import com.ruoyi.stuinfo.service.IStudentPunishService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 处罚查询Controller
 *
 * @author zc
 * @date 2025-05-18
 */
@RestController
@RequestMapping("/stuinfo/stupunment")
public class StudentPunishController extends BaseController
{
    @Autowired
    private IStudentPunishService studentPunishService;

    /**
     * 查询处罚查询列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:stupunment:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentPunish studentPunish)
    {
        String teacherId=getUsername();
        if("admin".equals(teacherId))
        {
            startPage();
            List<StudentPunish> list = studentPunishService.selectStudentPunishList(studentPunish);
            return getDataTable(list);
        }
        else
        {
            startPage();
            List<StudentPunish> list = studentPunishService.selectStudentPunishList_handteacher(teacherId);
            return getDataTable(list);
        }


    }

    /**
     * 导出处罚查询列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:stupunment:export')")
    @Log(title = "处罚查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentPunish studentPunish)
    {

        String teacherId=getUsername();
        if("admin".equals(teacherId))
        {
            List<StudentPunish> list = studentPunishService.selectStudentPunishList(studentPunish);
            ExcelUtil<StudentPunish> util = new ExcelUtil<StudentPunish>(StudentPunish.class);
            util.exportExcel(response, list, "处罚查询数据");
        }
        else
        {
            List<StudentPunish> list = studentPunishService.selectStudentPunishList_handteacher(teacherId);
            ExcelUtil<StudentPunish> util = new ExcelUtil<StudentPunish>(StudentPunish.class);
            util.exportExcel(response, list, "处罚查询数据");
        }



    }

    /**
     * 获取处罚查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:stupunment:query')")
    @GetMapping(value = "/{punishmentId}")
    public AjaxResult getInfo(@PathVariable("punishmentId") Long punishmentId)
    {
        return success(studentPunishService.selectStudentPunishByPunishmentId(punishmentId));
    }

    /**
     * 新增处罚查询
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:stupunment:add')")
    @Log(title = "处罚查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentPunish studentPunish)
    {
        return toAjax(studentPunishService.insertStudentPunish(studentPunish));
    }

    /**
     * 修改处罚查询
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:stupunment:edit')")
    @Log(title = "处罚查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentPunish studentPunish)
    {
        return toAjax(studentPunishService.updateStudentPunish(studentPunish));
    }

    /**
     * 删除处罚查询
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:stupunment:remove')")
    @Log(title = "处罚查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{punishmentIds}")
    public AjaxResult remove(@PathVariable Long[] punishmentIds)
    {
        return toAjax(studentPunishService.deleteStudentPunishByPunishmentIds(punishmentIds));
    }

    //模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {

        ExcelUtil<StudentPunish> util = new ExcelUtil<StudentPunish>(StudentPunish.class);
        util.importTemplateExcel(response, "用户数据");
    }

    @PreAuthorize("@ss.hasPermi('stuinfo:stupunment:adds')")
    @Log(title = "成绩详情", businessType = BusinessType.IMPORT)
    @PostMapping("/import")
    public AjaxResult excelImport(MultipartFile file) throws Exception {
        ExcelUtil<StudentPunish> util = new ExcelUtil<StudentPunish>(StudentPunish.class);
        List<StudentPunish> studentPunishes = util.importEasyExcel(file.getInputStream());
        return toAjax(studentPunishService.insertStudentPunishs(studentPunishes));
    }
}
